package org.bigk.invoices.utils;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bigk.invoices.Globals;
import org.bigk.invoices.model.User;

public class SessionUtils {
	/**
	 * Logger for this class
	 */
	private static final Log logger = LogFactory.getLog(SessionUtils.class);

	private SessionUtils() {
	}

	public static final User getUser(Map<String, Object> session) {
		return (User) session.get(Globals.SP_USER);
	}

	public static final boolean isLoggedIn(Map<String, Object> session) {
		if (logger.isDebugEnabled()) {
			logger.debug("isLoggedIn(Map<String,Object> session=" + session + ") - start");
		}

		if (session == null)
			return false;
		Boolean b = (Boolean) session.get(Globals.SP_LOGGED_FLAG);
		if (b == null)
			return false;

		boolean returnboolean = b.booleanValue();
		if (logger.isDebugEnabled()) {
			logger.debug("isLoggedIn(Map<String,Object>) - end - return value=" + returnboolean);
		}
		return returnboolean;
	}	
}
